<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head th:replace="admin/_fragments :: head(~{::title})">
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>新闻发布</title>
  <!-- Bootstrap Core CSS -->
  <link href="../css/bootstrap.min.css" rel="stylesheet">

  <!-- Custom CSS -->
  <link href="../css/main.css" rel="stylesheet">
  <link href="../css/style.css" rel="stylesheet">
  <link href="../css/responsive.css" rel="stylesheet">
  <link href="../fonts/flaticon.css" rel="stylesheet">
  <link href="../css/ionicons.min.css" rel="stylesheet">

  <!-- JavaScripts -->
  <script src="../js/modernizr.js"></script>

  <!-- Online Fonts -->
  <link href="https://fonts.googleapis.com/css?family=Merriweather:300,400,700,900|Montserrat:300,400,500,600,700,800" rel="stylesheet">
  <link href="https://use.fontawesome.com/releases/v5.0.8/css/all.css" rel="stylesheet">

  <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
  <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
  <!--[if lt IE 9]>
  <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
  <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
  <![endif]-->
</head>
<body>



  <!--中间内容-->
  <div  class="m-container m-padded-tb-big">
    <div class="ui container">
      <form id="blog-form" action="#" th:object="${blog}" th:action="@{/admin/blogs}" method="post" class="ui form">
        <input type="hidden" name="published" th:value="*{published}">
        <input type="hidden" name="id" th:value="*{id}">

        <div class="required field">
          <div id="md-content" style="z-index: 1 !important;">
            <textarea placeholder="博客内容" name="content" style="display: none" th:text="*{content}"></textarea>
          </div>
        </div>


        <div class="required field">
          <div class="ui left labeled input">
            <label class="ui teal basic label">首图</label>
            <input type="text" name="firstPicture" th:value="*{firstPicture}" placeholder="首图引用地址">
          </div>
        </div>

        <div class="required field">
          <textarea name="description" th:text="*{description}" placeholder="博客描述..." maxlength="200"></textarea>
        </div>


        <div class="ui error message"></div>

        <div class="ui right aligned container">
          <button type="button" class="ui button" onclick="window.history.go(-1)" >返回</button>
          <button type="button" id="save-btn" class="ui secondary button">保存</button>
          <button type="button" id="publish-btn" class="ui teal button">发布</button>
        </div>

      </form>
    </div>
  </div>

  <br>
  <br>

  <!--/*/<th:block th:replace="admin/_fragments :: script">/*/-->
  <script src="https://cdn.jsdelivr.net/npm/jquery@3.2/dist/jquery.min.js"></script>
  <script src="https://cdn.jsdelivr.net/semantic-ui/2.2.4/semantic.min.js"></script>
  <!--/*/</th:block>/*/-->


  <script>

    //初始化Markdown编辑器
    var contentEditor;
    $(function() {
      contentEditor = editormd("md-content", {
        width   : "100%",
        height  : 640,
        syncScrolling : "single",
//        path    : "../static/lib/editormd/lib/"
        path    : "/lib/editormd/lib/"
      });
    });
    $('.menu.toggle').click(function () {
      $('.m-item').toggleClass('m-mobile-hide');
    });

    $('.ui.dropdown').dropdown({
      on : 'hover'
    });

    $('#save-btn').click(function () {
      $('[name="published"]').val(false);
      $('#blog-form').submit();
    });


    $('#publish-btn').click(function () {
      $('[name="published"]').val(true);
      $('#blog-form').submit();
    });



    $('.ui.form').form({
      fields : {
        title : {
          identifier: 'title',
          rules: [{
            type : 'empty',
            prompt: '标题：请输入博客标题'
          }]
        },
        content : {
          identifier: 'content',
          rules: [{
            type : 'empty',
            prompt: '标题：请输入博客内容'
          }]
        },
        typeId : {
          identifier: 'type.id',
          rules: [{
            type : 'empty',
            prompt: '标题：请输入博客分类'
          }]
        },
        /*firstPicture : {
          identifier: 'firstPicture',
          rules: [{
            type : 'empty',
            prompt: '标题：请输入博客首图'
          }]
        },*/
        description : {
          identifier: 'description',
          rules: [{
            type : 'empty',
            prompt: '标题：请输入博客描述'
          }]
        }
      }
    });

  </script>
</body>
</html>